import router from './index.js'
import store from '@/store/index.js'

const pageList = ['/setting', '/question']

// 访问权限
// const vipList = ['/setting']
router.beforeEach((to, from, next) => {
  const token = store.state.tokenInfo.token
  console.log(token)
  if (!token && pageList.includes(to.path)) {
    console.log('没有权限，不能访问')
    next('/login?backto=' + encodeURIComponent(to.fullPath))
  } else if (token && to.path === '/login') {
    console.log('已经登陆了，不能访问login')
    next('/')
  } else {
    next()
  }
})

export default router
